﻿/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2010 Laurent Berthelot
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package marcel.display.draw.shapes
{
	import flash.display.Graphics;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import marcel.display.draw.props.FillProps;
	import marcel.display.draw.props.LineProps;
	
	
	/**
	 * The StarShape class contains a static method that you can use to draw a star shape.
	* @author Laurent Berthelot
	*/
	public class StarShape extends BasicShape {
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		/**
		 * Non-instanciable class, only statics methods in StarShape class.
		 */
		public function StarShape(o:ConstructorAccess) {}
		
		//--------------------------------------------------------------------------
		//
		//  Public static methods
		//
		//--------------------------------------------------------------------------
		/**
		 * Draws a star.
		 * @param	graphics	Graphics object to draw on.
		 * @param	arms		Number of arm.
		 * @param	radius		Radius of the star.
		 * @param	radiusInner	Inner radius of the star.
		 * @param	fp			Fill properties.
		 * @param	lp			Line style properties.
		 */
		public static function drawShape(graphics:Graphics, arms:Number = 3, radius:Number = 0, radiusInner:Number = 0, fp:FillProps = null, lp:LineProps = null):Graphics {
			_lineStyle(graphics, lp);
			_beginFill(graphics, fp, new Rectangle( -radius >> 1, -radius >> 1, radius, radius));
			var i:Number, angle:Number;
			var p:Point = Point.polar(radius, 0);
			graphics.moveTo(p.x, p.y);
			for (i = 1; i < arms * 2; i++) {
				angle = i * Math.PI / arms;
				p = Point.polar(i % 2 === 0 ? radius : radiusInner, angle);
				graphics.lineTo(p.x, p.y);
			}
			_endFill(graphics);
			return graphics;
		}
	}
}
internal class ConstructorAccess {}